﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ModularFixture.CUiMFIntermediateUnitPlacementPointDlg
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.ModularFixture;

public class CUiMFIntermediateUnitPlacementPointDlg : TxForm
{
  private CApMFPrototypeGridRow m_prototypeGridRow;
  private TxFrame m_frame;
  private bool m_isValidFrame;
  private TxTransformation m_location;
  private IContainer components;
  private TxFrameEditBoxCtrl m_placementPointCtrl;
  private Button m_ok;
  private Button m_cancel;
  private Label label1;
  private TextBox m_resourceNameTextBox;
  private Label label2;

  internal CUiMFIntermediateUnitPlacementPointDlg(
    CApMFPrototypeGridRow prototypeGridRow,
    TxTransformation location)
  {
    this.InitializeComponent();
    this.m_prototypeGridRow = prototypeGridRow;
    this.m_location = location;
    if (TxTransformation.op_Inequality(prototypeGridRow.IntermediateUnitPlacementPoint, (TxTransformation) null))
    {
      this.m_placementPointCtrl.SetLocation(prototypeGridRow.IntermediateUnitPlacementPoint);
      this.m_isValidFrame = true;
      this.CreateFrameInGraphicViewer(prototypeGridRow.IntermediateUnitPlacementPoint);
    }
    this.m_resourceNameTextBox.Text = prototypeGridRow.Name;
    this.m_placementPointCtrl.ListenToPick = true;
    this.m_placementPointCtrl.Focus();
  }

  private void CUiMFIntermediateUnitPlacementPointDlg_Load(object sender, EventArgs e)
  {
    this.m_placementPointCtrl.Focus();
  }

  private void CUiMFIntermediateUnitPlacementPointDlg_FormClosed(
    object sender,
    FormClosedEventArgs e)
  {
    this.DeleteFrame();
  }

  private void m_ok_Click(object sender, EventArgs e)
  {
    this.m_prototypeGridRow.IntermediateUnitPlacementPoint = !this.m_isValidFrame ? (TxTransformation) null : this.m_placementPointCtrl.GetLocation();
    ((Form) this).Close();
  }

  private void m_cancel_Click(object sender, EventArgs e) => ((Form) this).Close();

  private void m_placementPointCtrl_Picked(object sender, TxFrameEditBoxCtrl_PickedEventArgs args)
  {
    TxTransformation currentLocation = TxTransformation.op_Multiply(this.m_location.Inverse, args.Location);
    this.m_placementPointCtrl.SetLocation(currentLocation);
    this.CreateFrameInGraphicViewer(currentLocation);
  }

  private void m_placementPointCtrl_ValidFrameSet(
    object sender,
    TxFrameEditBoxCtrl_ValidFrameSetEventArgs args)
  {
    this.m_isValidFrame = true;
    this.CreateFrameInGraphicViewer(this.m_placementPointCtrl.GetLocation());
  }

  private void m_placementPointCtrl_InvalidFrameSet(
    object sender,
    TxFrameEditBoxCtrl_InvalidFrameSetEventArgs args)
  {
    this.m_isValidFrame = false;
    this.DeleteFrame();
  }

  internal void CreateFrameInGraphicViewer(TxTransformation currentLocation)
  {
    this.DeleteFrame();
    this.m_frame = TxFrameEx.CreateFrame(new TxFrameCreationDataEx("placementPointTemp", TxTransformation.op_Multiply(this.m_location, currentLocation), true));
    TxApplication.RefreshDisplay();
  }

  internal void DeleteFrame()
  {
    if (!TxFrame.op_Inequality(this.m_frame, (ITxObject) null))
      return;
    this.m_frame.Delete();
    this.m_frame = (TxFrame) null;
    TxApplication.RefreshDisplay();
  }

  internal TxTransformation PlacementPoint => this.m_placementPointCtrl.GetLocation();

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiMFIntermediateUnitPlacementPointDlg));
    this.m_placementPointCtrl = new TxFrameEditBoxCtrl();
    this.m_ok = new Button();
    this.m_cancel = new Button();
    this.label1 = new Label();
    this.m_resourceNameTextBox = new TextBox();
    this.label2 = new Label();
    ((Control) this).SuspendLayout();
    this.m_placementPointCtrl.EnableRelativeToWorkingFrameCoordinates = true;
    this.m_placementPointCtrl.ListenToPick = false;
    ((Control) this.m_placementPointCtrl).Location = new Point(102, 45);
    ((Control) this.m_placementPointCtrl).Name = "m_placementPointCtrl";
    ((Control) this.m_placementPointCtrl).Size = new Size(156, 24);
    ((Control) this.m_placementPointCtrl).TabIndex = 0;
    this.m_placementPointCtrl.ValidFrameSet += new TxFrameEditBoxCtrl_ValidFrameSetEventHandler(this.m_placementPointCtrl_ValidFrameSet);
    this.m_placementPointCtrl.Picked += new TxFrameEditBoxCtrl_PickedEventHandler(this.m_placementPointCtrl_Picked);
    this.m_placementPointCtrl.InvalidFrameSet += new TxFrameEditBoxCtrl_InvalidFrameSetEventHandler(this.m_placementPointCtrl_InvalidFrameSet);
    this.m_ok.DialogResult = DialogResult.OK;
    this.m_ok.Location = new Point(102, 88);
    this.m_ok.Name = "m_ok";
    this.m_ok.Size = new Size(75, 23);
    this.m_ok.TabIndex = 1;
    this.m_ok.Text = "OK";
    this.m_ok.UseVisualStyleBackColor = true;
    this.m_ok.Click += new EventHandler(this.m_ok_Click);
    this.m_cancel.DialogResult = DialogResult.Cancel;
    this.m_cancel.Location = new Point(183, 88);
    this.m_cancel.Name = "m_cancel";
    this.m_cancel.Size = new Size(75, 23);
    this.m_cancel.TabIndex = 2;
    this.m_cancel.Text = "Cancel";
    this.m_cancel.UseVisualStyleBackColor = true;
    this.m_cancel.Click += new EventHandler(this.m_cancel_Click);
    this.label1.AutoSize = true;
    this.label1.Location = new Point(9, 19);
    this.label1.Name = "label1";
    this.label1.Size = new Size(87, 13);
    this.label1.TabIndex = 3;
    this.label1.Text = "Resource Name:";
    this.m_resourceNameTextBox.Location = new Point(102, 16 /*0x10*/);
    this.m_resourceNameTextBox.Name = "m_resourceNameTextBox";
    this.m_resourceNameTextBox.ReadOnly = true;
    this.m_resourceNameTextBox.Size = new Size(156, 20);
    this.m_resourceNameTextBox.TabIndex = 4;
    this.label2.AutoSize = true;
    this.label2.Location = new Point(9, 52);
    this.label2.Name = "label2";
    this.label2.Size = new Size(87, 13);
    this.label2.TabIndex = 5;
    this.label2.Text = "Placement Point:";
    ((Form) this).AcceptButton = (IButtonControl) this.m_ok;
    ((ContainerControl) this).AutoScaleDimensions = new SizeF(6f, 13f);
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Form) this).CancelButton = (IButtonControl) this.m_cancel;
    ((Form) this).ClientSize = new Size(268, 120);
    ((Control) this).Controls.Add((Control) this.label2);
    ((Control) this).Controls.Add((Control) this.m_resourceNameTextBox);
    ((Control) this).Controls.Add((Control) this.label1);
    ((Control) this).Controls.Add((Control) this.m_cancel);
    ((Control) this).Controls.Add((Control) this.m_ok);
    ((Control) this).Controls.Add((Control) this.m_placementPointCtrl);
    ((Form) this).FormBorderStyle = FormBorderStyle.FixedDialog;
    ((Form) this).Icon = (Icon) componentResourceManager.GetObject("$this.Icon");
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CUiMFIntermediateUnitPlacementPointDlg);
    ((Control) this).Text = "Intermediate Unit Placement Point";
    ((Form) this).TopMost = true;
    ((Form) this).ShowIcon = false;
    ((Form) this).Load += new EventHandler(this.CUiMFIntermediateUnitPlacementPointDlg_Load);
    ((Form) this).FormClosed += new FormClosedEventHandler(this.CUiMFIntermediateUnitPlacementPointDlg_FormClosed);
    ((Control) this).ResumeLayout(false);
    ((Control) this).PerformLayout();
  }
}
